import common from '../vendor/common'
import '../scss/building_detail.scss'
import { buildDetail } from '../vendor/api'
import houseDetailList from '../components/houseDetailList'
import selfMap from '../components/detailMap'
const detailBanner = common.detailBanner
const featureBanner = common.featureBanner
const mui = common.mui
const Vue = common.Vue
var Vuebuilding = null //详情页数据Vue对象
var ids = '' // 接受传递的id
  Vuebuilding = new Vue({
      el: '#Vuebuilding',
      components: { houseDetailList, detailBanner, featureBanner, selfMap },
      data: {
          list: {
              describe: '', // 楼盘介绍
              unit_price: '', //租金
              total_price: '', //总价格
              constru_acreage: '', //面积
              station_number: '', //工位数
              payment_type: '', //支付方式
              renovation: '', //装修
              register_company: '', //注册公司
              check_in_time: '', //入住时间
              shortest_lease: '', //最短租期
              floor: '', //楼层
              house_type: '', // 户型
              office_building_type: '', //类型
              orientation: '', //朝向
              open_bill: '', //可否开发票
              split: '', //可否拆分
              name: '', // 名称
              rent_price: '', // 租金        
              address: '', //地址
              years_cn: '', // 建筑年代
              acreage_cn: '', // 总面积
              building_block_num_cn: '', // 楼座数量
              parking_num_cn: '', // 车位数量
              developer: '', // 开发商
              parking_fee_cn: '', // 停车费
              greening_rate_cn: '', // 绿化率
              company: '', // 入驻企业
              gps: ['114.31', '30.52'], // gps数据
              label_cn: '' // 是否优选
          },
          other: [],
          banner: [],
          bannerImg: []
      },
      methods: {
        // 更多数据加载后调用方法改变后
        moreChange: function() {
        }
      }
  })
try{
window.addEventListener('createdData', function(event) {
    const item = event.detail.item
    plus.webview.currentWebview().setStyle({titleNView:{titleText:item.name}})
    window.scroll(0, 0)
    ids = item.guid
    console.log(item.company)
    for (var p in Vuebuilding.list) {
        if (p === 'company' && item[p] !== null) {
        Vuebuilding.list.company = item[p].join(',')
        } else {
        Vuebuilding.list[p] = item[p]
        }
    }
    Vuebuilding.bannerImg = item.pic_url
    Vuebuilding.banner = item.feature_name_pic
    Vuebuilding.$refs.houseDetailList.init(ids)
})
mui.plusReady(function(){
    mui.init({
        swipeBack:true, //启用右滑关闭功能
        pullRefresh : {
          container:"#pullrefresh",
          down: {
            style:'circle',//必选，下拉刷新样式，目前支持原生5+ ‘circle’ 样式
            contentrefresh : "正在刷新...",
            color:'#2BD009', //可选，默认“#2BD009” 下拉刷新控件颜色
            height:50,//可选,默认50px.下拉刷新控件的高度
            range:'100px', //可选 默认100px,控件可下拉拖拽的范围
            offset:'0px', //可选 默认0px,下拉刷新控件的起始位置
            callback: function() {
                init_index()
                mui('#pullrefresh').pullRefresh().endPulldownToRefresh()
            }
          }
        }
    })
  
})

} catch(e){
    console.log('building_detail出错了')
}
function init_index(){
	window.scrollTo(0,0)
	Vuebuilding.$refs.houseDetailList.init(ids)
	buildDetail(ids).then(res => {
		for (var p in Vuebuilding.list) {
			if (p === 'company' && item[p] !== null) {
                Vuebuilding.list.company = item[p].join(',')
            } else {
                Vuebuilding.list[p] = item[p]
            }
		}
		Vuebuilding.banner = res.data.feature_name_pic
		Vuebuilding.bannerImg = res.data.pic_url
	})
	Vuebuilding.$refs.houseDetailList.init(ids)
}
